const user = document.querySelector("#username");
const psw = document.querySelector("#password");
user.addEventListener("input", function() {
    const tips = document.querySelectorAll(".tips")
    const userInput = user.value;
    var regUsername = /^[\u4e00-\u9fa5]{2,10}$/;
    if (!regUsername.test(userInput)) {
        tips[0].style.display = "block";
        return false
    }
    tips[0].style.display = "none";
})
psw.addEventListener("input", function() {
    const tips = document.querySelectorAll(".tips")
    const pswInput = psw.value;
    var regPsw = /^\w{6,20}$/;
    if (!regPsw.test(pswInput)) {
        tips[1].style.display = "block";
        return false
    }
    tips[1].style.display = "none";
})
const submit = document.querySelector('.submit');
submit.onclick = function() {
    ajax({
        url: '../php/login.php',
        type: 'post',
        data: {
            username: user.value,
            password: psw.value,
        },
        dataType: 'json',
    }).then(
        function(res) {
            console.log(res.code);
            if (res.code === 0) {
                console.log("登录失败");
            } else {
                window.open('../html/shouye.html');
            }
        })
}